﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using InfoJetSoft.Service.Entity;
using InfoJetSoft.Service.Util;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Security.Principal;
using System.Security.Cryptography.X509Certificates;

//CID 2081 //2014.01.11 //Begin
namespace InfoJetSoft.Service.Worker
{
    class ListAttachmentFileDeleteWorker
    {
        public static void deleteFile(Form form)
        {
            string attachmentId = form.ParamTable["xdoc_param_list_attachment_id"] as string;
            XmlElement attachmentElement = DOMUtil.findNodeByJetId(form, attachmentId) as XmlElement;
            if (attachmentElement != null)
            {
                string fileName = form.ParamTable["xdoc_param_delete_list_attachment_file"] as string;
                string fileName1 = "/" + fileName;
                string fileName2 = "\\" + fileName;
                string value = attachmentElement.InnerText;
                if (value.StartsWith(JetConstant.xdListAttachments)) {
                    string[] parts = value.Split(new char[] { '\n' });
                    string newValue = JetConstant.xdListAttachments;
                    for (int i = 1; i < parts.Length; i++)
                    { 
                        string part = parts[i];
                        if (part.EndsWith(fileName1) || part.EndsWith(fileName2))
                        {
                            //skip
                        }
                        else
                        {
                            newValue = newValue + "\n" + part;
                        }
                    }
                    attachmentElement.InnerText = newValue;
                }
            }
        }
    }
}
//CID 2081 //2014.01.11 //End